package cn.edu.hit.rest.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
//import com.fasterxml.jackson.core.JsonProcessingException;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import net.sf.json.JSONObject;

import java.beans.Transient;
import java.util.*;
import java.util.stream.Collectors;

public class MatchResult {
    @JsonIgnore
    private long id;

    private String code;
    private String desc1;
    private String treatment;
    private OpType op;
    private List<MatchResult> child = new ArrayList<>();
    private boolean value = false;
    private double probability = 100.0;
    private List<Integer> ceDianList = new ArrayList<>();
    private double zhixinDu = 100.0;
    private boolean unknown = false;
    private boolean empty = false;

    @Transient
    @JsonIgnore
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc1() {
        return desc1;
    }

    public void setDesc1(String desc1) {
        this.desc1 = desc1;
    }

    public String getTreatment() {
        return treatment;
    }

    public void setTreatment(String treatment) {
        this.treatment = treatment;
    }

    public OpType getOp() {
        return op;
    }

    public void setOp(OpType op) {
        this.op = op;
    }

    public List<MatchResult> getChild() {
        return child;
    }

    public void setChild(List<MatchResult> child) {
        this.child = child;
    }

    public boolean isValue() {
        return value;
    }

    public void setValue(boolean value) {
        this.value = value;
    }

    public double getProbability() {
        return probability;
    }

    public void setProbability(double probability) {
        this.probability = probability;
    }

    public List<Integer> getCeDianList() {
        return ceDianList;
    }

    public void setCeDianList(List<Integer> ceDianList) {
        this.ceDianList = ceDianList;
    }

    public double getZhixinDu() {
        return zhixinDu;
    }

    public void setZhixinDu(double zhixinDu) {
        this.zhixinDu = zhixinDu;
    }

    public boolean isUnknown() {
        return unknown;
    }

    public void setUnknown(boolean unknown) {
        this.unknown = unknown;
    }

    public boolean isEmpty() {
        return empty;
    }

    public void setEmpty(boolean empty) {
        this.empty = empty;
    }

    @JsonIgnore
    public Map asMap(){
        Map json = new LinkedHashMap();
        json.put("code",code);
        json.put("desc1",desc1);
        json.put("treatment",treatment);
        json.put("op",op);
        json.put("child",(child==null||child.size()==0)?null:child.stream().map(MatchResult::asMap).collect(Collectors.toList()));
        json.put("value",value?"TRUE":"FALSE");
        json.put("probability",probability*100);
        json.put("ceDianList","["+ceDianList.stream().map(Object::toString).collect(Collectors.joining(","))+"]");
        json.put("zhixinDu",zhixinDu*100);
        json.put("empty",empty);
        json.put("unknown",unknown);
        json.put("__id__",id);
        return json;
    }

//    public static void main(String[] args) {
//        MatchResult result = new MatchResult();
//        result.setCode("V221012L9");
//        result.setDesc1("测试测试");
//        result.setValue(true);
//        result.setProbability(0.25);
//        result.setCeDianList(Arrays.asList(123,234,124,235));
//        result.setZhixinDu(0.123);
//        result.setEmpty(true);
//        System.out.println(result.asMap());
//    }
}
